<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html style="height: auto; min-height: 100%;">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>天津市西青医院满意度调查问卷</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<%=basePath%>dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="<%=basePath%>dist/css/skins/_all-skins.min.css">
    <!-- Validator style -->
    <link href="<%=basePath %>bootstrap/bootstrapvalidator/dist/css/bootstrapValidator.min.css" rel="stylesheet"/>
    <%--<link href="https://unpkg.com/bootstrap-table@1.14.2/dist/extensions/group-by-v2/bootstrap-table-group-by.css" rel="stylesheet">--%>
    <link href="<%=basePath %>bootstrap/bootstrap-table/dist/extensions/group-by-v2/bootstrap-table-group-by.css" rel="stylesheet"/>
    <link href="<%=basePath %>bootstrap/bootstrap-table/dist/bootstrap-table.css" rel="stylesheet"/>
    <link href="<%=basePath %>bootstrap/bootoast/dist/bootoast.min.css" rel="stylesheet"/>
</head>
<body class="skin-blue sidebar-mini" style="height: auto; min-height: 100%;">
<div class="wrapper" style="height: auto; min-height: 100%;">
    <!-- header头部页面 -->
    <jsp:include page="../commend/top.jsp"/>
    <!-- Left side column. contains the logo and sidebar -->
    <jsp:include page="../commend/left.jsp"/>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper" style="min-height: 800px;">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>

                <small>科室评价关系管理</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li class="active">科室评价关系管理</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- Info boxes -->
            <!-- Main row -->
            <div class="row">
                <div class="col-md-12">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title">科室列表</h3>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body ">
                            <div class="row ">
                                <div class="col-md-12">
                                    <div id="toolbar" class="btn-group">
                                    <button id="btn_save" type="button" class="btn btn-default " >复制评价科室</button>
                                </div>
                                    <table
                                            id="dutytable"
                                            data-toggle="table"
                                            data-toolbar="#toolbar"
                                            data-url="../../dept/selectAllTDeptIsEnable"
                                            data-cache="false"
                                            data-click-to-select="true"
                                            data-search="true"
                                            style="font-size:100%;">
                                        <thead>
                                        <tr>
                                            <th data-field="state" data-checkbox="true"></th>
                                            <th data-field="groupName" data-align="center" data-width="20%" data-valign="middle">科室类别</th>
                                            <th data-field="name" data-align="center" data-width="30%" data-valign="middle">科室名称</th>
                                            <th data-field="id"  data-align="center" data-valign="middle" data-formatter="operateformat" data-events="operateEvent">操作</th>
                                        </tr>
                                        </thead>
                                    </table>
                                </div>
                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- ./box-body -->
                        <div class="box-footer">
                            <div class="row">

                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- /.box-footer -->
                    </div>
                    <!-- /.box -->
                </div>
            </div>
            <!-- /.row -->
        </section>
        <!--关联的科室model -->
        <div class="modal fade" id="modalTable" tabindex="-1" role="dialog"  aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">评价科室</h4>
                    </div>
                    <div class="modal-body">
                        <table id="evaldepttable"
                               data-toggle="table"
                               data-url="../../dept/selectAllTDeptIsEnable"
                               data-group-by="true"
                               data-group-by-field="groupName"
                               data-checkbox-header="false"
                               data-click-to-select="true"
                               data-height="450"
                               style="font-size:100%;">
                            <thead>
                            <tr>
                                <th data-field="state" data-checkbox="true"></th>
                                <th data-field="groupName" data-align="center" data-valign="middle">科室类别</th>
                                <th data-field="name" data-align="center" data-valign="middle">科室名称</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default"  id="btn_sure">确定</button>
                    </div>
                </div>
            </div>

        </div>
        <!--拷贝关联科室model -->
        <div class="modal fade" id="modalCopyDutyTable" tabindex="-1" role="dialog"  aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">参考科室</h4>
                    </div>
                    <div class="modal-body">
                        <table id="copyDutyTable"
                               data-toggle="table"
                               data-url="../../dept/selectAllTDeptIsEnable"
                               data-checkbox-header="false"
                               data-click-to-select="true"
                               data-single-select="true"
                               data-height="450"
                               data-search="true"
                               style="font-size:100%;">
                            <thead>
                            <tr>
                                <th data-field="state" data-checkbox="true"></th>
                                <th data-field="name" data-align="center" data-valign="middle">科室名称</th>
                                <th data-field="groupName" data-align="center" data-valign="middle">科室类别</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default"  id="btn_copy">确定</button>
                    </div>
                </div>
            </div>

        </div>
        <!--关联科室调查问卷model -->
        <div class="modal fade" id="modalDutyPaperTable" tabindex="-1" role="dialog"  aria-hidden="true">
            <div class="modal-dialog" style="width: 800px">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">可以评价的科室及其评价问卷</h4>
                    </div>
                    <div class="modal-body">
                        <div id="dutypapertoolbar" class="btn-group">
                            <button id="btn_adddutypaper" type="button" class="btn btn-default " >添加调查问卷</button>
                        </div>
                        <table id="dutyPaperTableTable"
                               data-toolbar="#dutypapertoolbar"
                               data-toggle="table"
                               data-click-to-select="true"
                               data-height="450"
                               data-search="true"
                               data-sortable="true"
                               style="font-size:100%;">
                            <thead>
                            <tr>
                                <th data-field="state" data-checkbox="true"></th>
                                <th data-field="name" data-align="center" data-valign="middle" data-sortable="true">科室名称</th>
                                <th data-field="groupName" data-align="center" data-valign="middle" data-sortable="true">科室类别</th>
                                <th data-field="tTestPaper.name" data-align="center" data-valign="middle" data-formatter="papernameformat" >调查问卷</th>
                                <th data-field="tTestPaper.name" data-align="center" data-valign="middle" data-formatter="lengthformat" >问题</th>
                            </tr>
                            </thead>
                        </table>
                    </div>

                </div>
            </div>

        </div>
        <!--添加评价科室的调查问卷-->
        <div class="modal fade" id="modalEvalPaperTable" tabindex="-1" role="dialog"  aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">调查问卷</h4>
                    </div>
                    <div class="modal-body">
                        <table id="evalPaperTable"
                               data-toggle="table"
                               data-url="../../testPaper/selectAllPaper"
                               data-checkbox-header="false"
                               data-click-to-select="true"
                               data-single-select="true"
                               data-height="450"
                               style="font-size:100%;">
                            <thead>
                            <tr>
                                <th data-field="state" data-checkbox="true"></th>
                                <th data-field="name" data-align="center" data-valign="middle" data-formatter="papernameformat" >调查问卷名称</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default"  id="btn_dutypaper">确定</button>
                    </div>
                </div>
            </div>

        </div>

        <form name="form1" id="form1">
            <input type="hidden" name="deptId" id="deptId">
        </form>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <!-- footer-->
    <jsp:include page="../commend/footer.jsp"/>





</div>

<!-- jQuery 3 -->
<script src="<%=basePath %>bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="<%=basePath %>bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="<%=basePath %>bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="<%=basePath %>dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="<%=basePath %>dist/js/demo.js"></script>
<!-- Validator 3.3.7 -->
<script src="<%=basePath %>bootstrap/bootstrapvalidator/dist/js/bootstrapValidator.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrapvalidator/dist/js/language/zh_CN.js"></script>
<!-- bootstrap-table -->
<%--<script src="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.js"></script>--%>
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/bootstrap-table.js"></script>
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/extensions/group-by-v2/bootstrap-table-group-by.js"></script>

<%--<script src="https://unpkg.com/bootstrap-table@1.14.2/dist/extensions/group-by-v2/bootstrap-table-group-by.min.js"></script>--%>
<!-- bootbox -->
<script src="<%=basePath %>bootstrap/bootbox/bootbox.min.js"></script>
<script src="<%=basePath %>bootstrap/bootoast/dist/bootoast.min.js"></script>
<script src="<%=basePath %>bootstrap/commend/initcommend.js"></script>

<script type="text/javascript">
    $(function() {
        $('#modalTable').on('shown.bs.modal', function () {
            $("#evaldepttable").bootstrapTable('resetView')
        })
        $('#modalCopyDutyTable').on('shown.bs.modal', function () {
            $("#copyDutyTable").bootstrapTable('resetView')
        })
        $('#modalDutyPaperTable').on('shown.bs.modal', function () {
            $("#dutyPaperTableTable").bootstrapTable('resetView')
        })

        $("#modalEvalPaperTable").on('shown.bs.modal', function () {
            $("#evalPaperTable").bootstrapTable('resetView')
        })

        $("#btn_save").click(function () {
            $("#modalCopyDutyTable").modal({
                backdrop: 'static',
                keyboard: false
            });
        })

        $('#btn_sure').click(function () {
            var evalDeptIdList = new Array();
            $.each($("#evaldepttable").bootstrapTable('getSelections'),function (idx,obj) {
                evalDeptIdList.push(obj.id);
            })
            $.post(getRootPath_web()+'/deptMapper/addDeptMapper',{
                id:$("#deptId").val(),
                evalDeptIdList:evalDeptIdList
            },function (data) {
                if (data){
                    bootbox.alert("操作成功", function(){
                        setTimeout(function(){
                            $('#modalTable').modal('hide');
                        },320);
                    });
                } else {
                    bootbox.alert("操作失败");
                }
            },'json')

        })

        $('#btn_copy').click(function () {
            var copyToDeptIdList = new Array();
            $.each($("#dutytable").bootstrapTable('getSelections'),function (idx,obj) {
                copyToDeptIdList.push(obj.id);
            })
            var copyDutyId = $("#copyDutyTable").bootstrapTable('getSelections')[0].id
            $.post(getRootPath_web()+'/deptMapper/copyDeptMapper',{
                id:copyDutyId,
                copyToDeptIdList:copyToDeptIdList
            },function (data) {
                if (data){
                    bootbox.alert("操作成功", function(){
                        setTimeout(function(){
                            $('#modalCopyDutyTable').modal('hide');
                            $("#dutytable").bootstrapTable('refresh')
                        },320);
                    });
                } else {
                    bootbox.alert("操作失败");
                }
            },'json')
        })

        $("#btn_adddutypaper").click(function () {
            $("#modalEvalPaperTable").modal({
                backdrop: 'static',
                keyboard: false
            });
        })
        
        $("#btn_dutypaper").click(function () {
            var evaldutyIdList = new Array();
            var dutyPaperTableTable = $("#dutyPaperTableTable");
            var evalPaperTable = $("#evalPaperTable");
            $.each(dutyPaperTableTable.bootstrapTable('getSelections'),function (index,data) {
                evaldutyIdList.push(data.id)
            });
            var paperId = evalPaperTable.bootstrapTable('getSelections')[0].paperId;
            $.post(getRootPath_web()+'/deptMapper/addDeptPaper',{
                deptid:$("#deptId").val(),
                evaldutyIdList:evaldutyIdList,
                paperId:paperId
            },function (data) {
                if (data){
                    bootbox.alert("操作成功", function(){
                        $.post(getRootPath_web()+'/deptMapper/selectEvalDeptPaperByDeptId',{'id':$("#deptId").val()},function (data) {
                            $("#dutyPaperTableTable").bootstrapTable('load', data)
                        },'json')
                        setTimeout(function(){
                            $('#modalEvalPaperTable').modal('hide');
                        },320);
                    });
                } else {
                    bootbox.alert("操作失败");
                }
            },'json')
        })
    })

    function operateformat(value, row) {
        var buttonarray = new Array();
        buttonarray[0] = '<button type="button" class="RoleOfupdate btn btn-primary  btn-sm" style="margin-left: 10px">修改可以评价科室</button>';
        buttonarray[1] = '<button type="button" class="RoleOfalert btn btn-primary  btn-sm" style="margin-left: 10px">修改评价科室评价试卷</button>';

        return buttonarray.join('');
    }

    window.operateEvent = {
        'click .RoleOfupdate': function (e, value, row, index) {
            $.post(getRootPath_web()+'/deptMapper/findEvalDeptList',{'id':row.id},function (data) {
                $("#deptId").val(row.id);
                $.each($("#evaldepttable").bootstrapTable('getSelections'),function (idx,obj) {
                    $("#evaldepttable").bootstrapTable('uncheck', idx)
                });
                $.each(data,function (idx,obj) {
                    $("#evaldepttable").bootstrapTable('checkBy', {field: 'id', values: [obj]})
                })
                $("#modalTable").modal({
                    backdrop: 'static',
                    keyboard: false
                });
            },'json')


        },
        'click .RoleOfalert': function (e, value, row, index) {
            $.post(getRootPath_web()+'/deptMapper/selectEvalDeptPaperByDeptId',{'id':row.id},function (data) {
                $("#deptId").val(row.id);
                $("#dutyPaperTableTable").bootstrapTable('load', data)
                $("#modalDutyPaperTable").modal({
                    backdrop: 'static',
                    keyboard: false
                });
            },'json')


        }
    }
    
    /**
     *调查问卷问题数据格式化
     */
    function lengthformat(value, row) {
        var questionlist = '';
        if(row.tTestPaper != null){
            $.each(row.tQuestions,function (index,data) {
                questionlist+=data.content+'\r\n';
            })
            return "<span title ='"+questionlist+"'>问题...</span>"
        }
       return '';

    }

    /**
     * 调查问卷名称数据格式化
     */
    function papernameformat(value, row) {
        value=value?value:'';
        var length=value.length;
        if(length>25){
            length=24;
            return "<span title ='"+value+"'>"+value.substring(0,length)+"...</span>"
        }
        return "<span title ='"+value+"'>"+value.substring(0,length)+"</span>"
    }
</script>
</body>
</html>
